package com.aaa.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface S_NewsDao {


    @Select("<script>SELECT news.id,news.title,news.type,type.`name`,news.`issuer`,news.release_time,news.state,news.content " +
            " from news,type " +
            " where type.id=news.type"+
            "<if test=\"title!=null and title!=''\"> and title like concat('%',#{title},'%')</if></script>")
    List<Map> selNews(Map map);

    @Select("<script>select count(id) from news" +
            " where 1=1 <if test=\"id!=null and id!=0\"> and id = #{id}</if></script>")
    Integer getCount(Map map);

    @Insert("insert into news(title,type,content,issuer,state) values(#{title},#{type},#{content},#{issuer},#{state})")
    int addNews(Map map);

    @Update("update news set title=#{title},type=#{type},content=#{content},issuer=#{issuer},state=#{state} where id=#{id}")
    int updateNews(Map map);

    @Delete("delete from news where id=#{id}")
    int delNews(Integer id);


    @Select("select * from type")
    List<Map> selName();

    @Update("update news set state=1 where id=#{id}")
    int subCheck(Integer id);

    //推荐阅读
    @Select("SELECT * FROM news where type=2 and state=2 ")
    List<Map> selectTitle();

    //地方动态
    @Select("SELECT * FROM news where type=1 and state=2 ")
    List<Map> selectTitledf();

    //志愿服务
    @Select("SELECT * FROM news where type=3 and state=2 ")
    List<Map> selectTitlezy();
}
